<template>
  <div class="publicBox" id="equipmentCSS ">
          <div class="boxItem " id="publicSearch">

<el-form ref="form" :inline="true"  class="demo-form-inline">

<el-form-item label="设备类型">
  <el-select v-model="oneSelectType" filterable  placeholder="全部" class="pubSlt">
    <el-option
      v-for="item in deviceTyp"
      :key="item.id"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
  </el-form-item>

 <el-form-item>
            <el-button class="pubBtnBlue" @click="getMent" type="primary">查询</el-button>
            <el-button class="pubBtnGree" type="primary" @click="addMenter">新建</el-button>
  </el-form-item>

</el-form>
</div>
          <public-table class="colum" 
           @handleChange="handleChange"
           @changePage="changePage"
           :columnDefs="columnDefs" 
           :tableData="tableData" 
           :order=true
           :btn="['delete','enable']"
           ></public-table>
  </div>
</template>

<script>
import publicTable from "@/components/public/publicTable.vue"
import * as API from "@api/equipmenter.js"
export default {
  components: {
         publicTable
  },
  data() {
    return {
        columnDefs :[
            {headerName: '设备类型', field: 'typename',width:86},
            {headerName: '品牌', field: 'brandname',width:200},
            {headerName: '设备型号', field: 'model',width:300},
            {headerName: '设备名称', field: 'name',width:300},
            {headerName: '创建时间', field: 'createtime',width:120},
            {headerName: '当前状态', field: 'statusname',width:90}
        ],
        tableData: [],
        deviceTyp: [],
        pageNum:1,
        pageSize:100,
        oneSelectType:null,
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {


  },
  // 监控data中的数据变化
  watch: {


 },
  methods: {
     changePage(pageSize,pageNum){
        this.pageSize=pageSize;this.pageNum=pageNum
        this.getMent()
     },
     addMenter(){
       this.$router.push({path:"/platform/equipment/equipmentNewbuild"})
     },
     async getMent(){
       let params={page:this.pageNum,size:this.pageSize,typeid:this.oneSelectType}
       let res=await API.getMent(params)
         if(res.IsPositive){
                  this.tableData=res.Data
                }else{
                  this.$message.error({message:res.ErrorCode})
                }
     },
     async handleChange(index,row){   //状态改变
              if(index==1) row.status=2
              if(index==2) row.status=3
              await API.editMent(row).then(res=>{
                if(res.IsPositive){
                  this.$message.success({message:"操作成功"})
                  this.getMent()
                }else{
                  this.$message.error({message:res.ErrorCode})
                }
              })

    },
  },
  async created() {
      this.deviceTyp = await this.$getDeviceType(2)
      this.getMent()
  },
  computed:{

  },
  mounted() {

  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='less' scoped>
@import "../../styles/less/public.less";
  #equipmentCSS{
    .boxItem{
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      .demo-form-inline{
        align-items: center;
      }
      .itemp{
      font-size: 16px;
      } 
    } 
  }
</style>